package cn.jsj.fixed.asset;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.jsj.pojo.TblFixedAssets;
import cn.jsj.utils.SysLogger;

/**
 * 搜索固定资产信息处理类
 * @author LI
 *
 */
 public class SearchExistAsset extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {
	 public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		 // 调试信息
		 cn.jsj.utils.SysLogger.PrintInfo("搜索固定资产信息！！！");

		 //获取参数
		 String sBuyTime=request.getParameter("sBuyTime").trim();
		 String eBuyTime=request.getParameter("eBuyTime").trim();
		 String assetName=request.getParameter("assetName").trim();
		 assetName=new String(assetName.getBytes("ISO-8859-1"),"UTF-8");
		 //如果没有输入时间
		 if(eBuyTime.equalsIgnoreCase("undefined")){
			 eBuyTime="";
		 }
		 if(sBuyTime.equalsIgnoreCase("undefined")){
			 sBuyTime="";
		 }


		//获得参数：1.第几条开始。2.一页显示几条
		int startNumb=Integer.parseInt(request.getParameter("start"));
		int totalNumb=Integer.parseInt(request.getParameter("limit"));
		//调试信息
		cn.jsj.utils.SysLogger.PrintInfo("start---->"+startNumb+"   total--------->"+totalNumb+"   "+assetName+"   "+sBuyTime+"  "+eBuyTime);

		//新建后台往DB的参数类
		cn.jsj.bgtodb.SearchFixedAssetProperty sfap=new cn.jsj.bgtodb.SearchFixedAssetProperty();
		sfap.setAssetName(assetName);
		sfap.setEBuyTime(eBuyTime);
		sfap.setSBuyTime(sBuyTime);
		sfap.setStartNumb(startNumb);
		sfap.setTotalNumb(totalNumb);

		//获得符合条件固定资产信息条数
		cn.jsj.dao.TblFixedAssetsDAO tfad=new cn.jsj.dao.TblFixedAssetsDAO();
		int fixedAssetNumb=tfad.getSearchFixedAssetNumb(sfap);

		//调试信息
		cn.jsj.utils.SysLogger.PrintInfo("符合条件信息条数----------->"+fixedAssetNumb);

		//固定资产信息队列
		java.util.List<TblFixedAssets> fixedAssetList=new java.util.LinkedList<TblFixedAssets>();
		fixedAssetList=tfad.getSearchFixedAsset(sfap);

		//调试信息
		cn.jsj.utils.SysLogger.PrintInfo("该页有几条信息------->"+fixedAssetList.size());
		//转化为JSON型数据
		cn.jsj.utils.ProduceJsonData pjd=new cn.jsj.utils.ProduceJsonData();
		String jsonResult=pjd.jsonFromList(fixedAssetList, fixedAssetNumb);

		//调试信息
		SysLogger.PrintInfo(jsonResult);
		//输出到客户端
		java.io.PrintWriter pw=response.getWriter();
		pw.println(jsonResult);
		pw.flush();
		pw.close();


	}
}